import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/core/utils/file_util.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/core/utils/log_util.dart';

class CustomTextWidget {
  /// 获取简单的列表字段显示,左右侧显示
  static Widget getTextRowView({required String title, required String value}) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          title,
          style: TextStyle(
            fontSize: 13.sp,
            height: 1.2,
            fontWeight: FontWeight.w400,
            color: const Color(0xffA5A6B5),
          ),
        ),
        AppGaps.hGap10,
        Expanded(
            child: Container(
          alignment: Alignment.centerRight,
          child: Text(
            value,
            style: TextStyle(
              fontSize: 12.sp,
              height: 1.2,
              fontWeight: FontWeight.w400,
              color: const Color(0xff495061),
            ),
          ),
        ))
      ],
    );
  }

  /// 获取简单的文件列表显示,左右侧显示
  static Widget getFileRowView({required String title, required List<String> fileList}) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          title,
          style: TextStyle(
            fontSize: 13.sp,
            height: 1.2,
            fontWeight: FontWeight.w400,
            color: const Color(0xffA5A6B5),
          ),
        ),
        AppGaps.hGap10,
        Expanded(
            child: SingleChildScrollView(
          child: Column(
              children: fileList.asMap().keys.map((index) {
            // 文件地址
            final String url = fileList[index];
            return Container(
              margin: EdgeInsets.only(top: index == 0 ? 0 : 10),
              alignment: Alignment.centerRight,
              child: _getAttachmentView(url),
            );
          }).toList()),
        ))
      ],
    );
  }

  /// 获取附件列显示
  static Widget _getAttachmentView(String url) {
    //本地文件名
    String currUrlName = '';
    try {
      currUrlName = url.toString().substring(25);
    } catch (e) {
      AppLogger.log(e.toString());
    }
    return Text(
      currUrlName,
      textAlign: TextAlign.right,
      style: TextStyle(
        fontSize: 13.sp,
        height: 1.2,
        color: const Color(0xFF5C6DFF),
      ),
    ).clickOnce(() {
      //打开文件
      FileUtils.openFile(Interface.fileUrl + url);
    });
  }
}
